KeyExists

The KeyExists method returns a BOOLEAN that indicates whether the registry contains the specified key. You can use this method to verify that a key exists before calling a method that uses the key, such as the Get method.

Syntax

KeyExists(FullKeyName)

Parameters

FullKeyName
A string that specifies the full name of the registry key.

This can be a key on either a local or a remote machine. Keys on a remote machine are specified by prefixing the key name with the machine name. For example:

\\RemoteMachine\HKLM\Software\MyProg

Return Value

A BOOLEAN that indicates whether the specified key exists in the registry. A return value of TRUE indicates that the key is present in the registry. FALSE indicates that the key was not found.

Example

The following example uses the KeyExists method to verify that the HKLM\Software\MyCompany key exists before calling the GetExpand method to retrieve the named value MyPath from that key.
<% 
Set Reg = Server.CreateObject("IISSample.Registry")
 
MyKey = "HKLM\Software\MyCompany"
MyPath = "HKLM\Software\MyCompany\MyPath"
 
If KeyExists(MyKey) Then
    PathExpand = Reg.GetExpand(MyPath)
Else
    Session("Error") = "Key not found in the registry"
    Response.Redirect("http://www.mycompany.com/ErrorHandler.asp")
End If 
%>
 

Applies To

Registry Access Component

See Also

Get, GetExpand, ValueType